package org.example.springoauth2.resourceserver2.controller;

import lombok.AllArgsConstructor;
import org.example.springoauth2.resourceserver2.feign.RemoteResourceServer1HomeService;
import org.example.springoauth2.securitycommon.common.ApiResp;
import org.example.springoauth2.securitycommon.config.Inner;
import org.example.springoauth2.securitycommon.constants.SecurityConstants;
import org.example.springoauth2.securitycommon.entity.JdbcUser;
import org.example.springoauth2.securitycommon.util.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hzq
 * @date 2021/10/12 10:17
 */
@RestController
@RequestMapping("/index")
@AllArgsConstructor
public class IndexController {

    private final RemoteResourceServer1HomeService remoteResourceServer1HomeService;

    @Inner(false)
    @GetMapping("/info")
    public ApiResp<String> homeInfo() {
        return remoteResourceServer1HomeService.info(SecurityConstants.FROM_IN);
    }

    @GetMapping("/user")
    public ApiResp<JdbcUser> homeUser() {
        return remoteResourceServer1HomeService.user();
    }

    @GetMapping("/userInfo")
    public ApiResp<JdbcUser> userInfo() {
        return ApiResp.ofSuccess(SecurityUtils.getSysUser().getJdbcUser());
    }

}
